package tec;

abstract class PassagerAbstrait implements Passager
{
	private EtatPassager etatPassager;
	private String nom;
	private int destination;
	private Comportement comportementPassager;

	public PassagerAbstrait(String nom, int destination, TypeComportement comportement)
	{
		if(destination < 0)
			throw new IllegalArgumentException("destination negative");

		this.nom = nom;
		this.destination = destination;
		etatPassager = EtatPassager.etatDehors;

		switch(comportement){
			case CALME : 
				this.comportementPassager = new Calme();
				break;
			case NERVEUX : 
				this.comportementPassager = new Nerveux();
				break;
			case PRUDENT : 
				this.comportementPassager = new Prudent();
				break;
			case AGORAPHOBE : 
				this.comportementPassager  = new Agoraphobe();
				break;
			case POLI : 
				this.comportementPassager  = new Poli();
				break;
		}
	}

	public final int getDestination(){
		return destination;
	}

	protected final EtatPassager getEtatPassager(){
		return etatPassager;
	}

	public final String nom()
	{
		return nom;
	}

	public final boolean estAssis()
	{
		return etatPassager.estAssis();
	}

	public final boolean estDebout()
	{
		return etatPassager.estDebout();
	}

	public final boolean estDehors()
	{
		return etatPassager.estExterieur();
	}

	public final void accepterPlaceAssise()
	{
		etatPassager = EtatPassager.etatAssis;
	} 

	public final void accepterPlaceDebout()
	{
		etatPassager =  EtatPassager.etatDebout;
	}

	public final void accepterSortie()
	{
		etatPassager = EtatPassager.etatDehors;
	}

	abstract	protected void choixPlaceMontee(Bus b);

	protected void choixChangerPlace(Bus b, int arret){
		comportementPassager.choixChangerPlace(b, arret, this);
	}

	public final void monterDans(Transport b) throws TecInvalidException 
	{
		Bus bus = (Bus) b;
		if(!(bus instanceof Bus))
			throw new TecInvalidException("Error Bus", new IllegalStateException());
		choixPlaceMontee(bus);
	}

	public final void nouvelArret(Bus bus, int numeroArret) throws TecInvalidException	
	{
		if(this.destination < numeroArret)
			throw new TecInvalidException("Destination dépassée", new IllegalStateException(), this, numeroArret);
		else if(this.destination == numeroArret)
			bus.demanderSortie(this);

		choixChangerPlace(bus, numeroArret);	
	}


	@Override
		public String toString()
		{
			return nom + " " + etatPassager.toString();
		}

}
